cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/FigureA5.log", replace

clear all
set more off

mat Table1 = J(15, 10, -9)
mat Table2 = J(15, 10, -9)

use "RawData/anes_timeseries_cdf.dta", clear
keep if VCF0004 >= 1960

foreach variable of varlist VCF080* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF081* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF082* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF083* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF084* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF085* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF086* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF087* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF088* {
display "`variable'"
tab `variable' VCF0004
}

foreach variable of varlist VCF089* {
display "`variable'"
tab `variable' VCF0004
}

//
// Issue Positions
//

// 2-Point Scale
foreach variable of varlist VCF0805 VCF0808 VCF0816 VCF0826 VCF0828 VCF0829 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = `variable' - 1
}

// 2-Point Scale (1 to 5)
foreach variable of varlist VCF0833 VCF0878 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 4
}

// 2-Point Scale (reversed)
foreach variable of varlist VCF0819 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' =  2 - `variable' 
}

// 3-Point Scale
foreach variable of varlist VCF0814 VCF0815 VCF0827 VCF0886 VCF0887 VCF0888 /*
*/ VCF0889 VCF0890 VCF0891 VCF0892 VCF0893 VCF0894 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 2
}

// 4-Point Scale
foreach variable of varlist VCF0837 VCF0838 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 3
}

// 4-Point Scale (1, 2, 4, 5)
foreach variable of varlist VCF0818 VCF0867a VCF0876a VCF0877a {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 3 | /*
*/ `variable' == 7 | `variable' == 8 | `variable' == 9 
replace `variable' = 0 if `variable' == 1
replace `variable' = 1/3 if `variable' == 2
replace `variable' = 2/3 if `variable' == 4
replace `variable' = 1 if `variable' == 5
}

// 5-Point Scale
foreach variable of varlist VCF0879 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 4
}

// 5-Point Scale (reversed)
foreach variable of varlist VCF0844 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (5 - `variable') / 4
}


// 7-Point Scale
foreach variable of varlist VCF0806 VCF0809 VCF0811 VCF0817 /*
*/ VCF0827a VCF0830 VCF0832 VCF0834 VCF0839 VCF0841 VCF0842 VCF0843 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 6
}

//
// Ideology
//

// 97-Point Scale
foreach variable of varlist VCF0801 {
tab `variable' VCF0004
replace `variable' = . if `variable' == 98 | `variable' == 99 
replace `variable' = (`variable' - 1) / 96
}
//
// Economic Well Being
//

// 3-Point Scale (reversed)
foreach variable of varlist VCF0880 VCF0881 {
tab `variable' VCF0004
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (3 - `variable') / 2
}


local i = 0
foreach var of varlist VCF0816 VCF0826 VCF0828 VCF0829 VCF0833 VCF0878 /*
*/ VCF0819 VCF0814 VCF0815 VCF0827 VCF0886 VCF0887 VCF0888 VCF0889 VCF0890 /*
*/ VCF0891 VCF0892 VCF0893 VCF0894 VCF0837 VCF0838 VCF0867a VCF0876a VCF0877a /*
*/ VCF0879 VCF0844 VCF0806 VCF0809 VCF0811 VCF0817 VCF0827a VCF0830 VCF0832 /*
*/ VCF0834 VCF0839 VCF0841 VCF0842 VCF0843 VCF0805 VCF0808 VCF0818 VCF0801 /*
*/ VCF0880 VCF0881 {
local i = `i' + 1
display "`i'"
tab `var'
rename `var' Issue`i'
}

keep VCF0004 VCF0009z VCF0104 VCF0110 Issue* 
gen ID = _n
reshape long Issue, i(ID VCF0004 VCF0009z VCF0104 VCF0110) j(issuenum)
drop if missing(Issue)

// Drops ideology and economic perceptions
keep if issuenum <= 41

gen CollegeXIssue = Issue if VCF0110 == 4

collapse (mean) Issue CollegeXIssue [pweight = VCF0009z], by(issuenum VCF0004 VCF0104)
reshape wide Issue CollegeXIssue, i(issuenum VCF0004) j(VCF0104)

gen diff = Issue1 - Issue2
gen diff_college = CollegeXIssue1 - CollegeXIssue2

gen group = 1 if VCF0004 >= 1960 & VCF0004 <= 1968
replace group = 2 if VCF0004 >= 1970 & VCF0004 <= 1978
replace group = 3 if VCF0004 >= 1980 & VCF0004 <= 1988
replace group = 4 if VCF0004 >= 1990 & VCF0004 <= 1998
replace group = 5 if VCF0004 >= 2000 & VCF0004 <= 2012

egen decade_avg_diff = mean(diff), by(group)
egen decade_avg_diff_college = mean(diff_college), by(group)

// Default Issue Category
gen issuetype = 4

// Social Welfare Spending:
// VCF0805: Government Assistance with Medical Care (39)
// VCF0806: Government Health Insurance Scale (27)
// VCF0808: Guaranteed Jobs and Income (40)
// VCF0809: Guaranteed Jobs and Income Scale (28)
// VCF0830: Aid to Blacks Scale (32)
// VCF0839: Government Services-Spending Scale (35)
// VCF0886: Federal Spending- Poor/Poor People (11)
// VCF0887: Federal Spending- Child Care (12)
// VCF0889: Federal Spending- Research/Fight Aids (14)
// VCF0890: Federal Spending- Public Schools (15)
// VCF0893: Federal Spending- The Homeless (18)
// VCF0894: Federal Spending- Welfare (19)
foreach num of numlist 39 27 40 28 32 35 11 12 14 15 18 19 {
replace issuetype = 1 if issuenum == `num'
}
// Use of Force:
// VCF0826: Did U.S. Do  Right Thing Getting Involved in War (2)
// VCF0827: How Should  U.S. Proceed in Current War (10)
// VCF0827a: U.S. Stand in Vietnam Scale (31)
// VCF0828: Should Government Cut Military Spending (3)
// VCF0841: Cooperation with U.S.S.R. Scale (36)
// VCF0843: Defense Spending Scale (38)
// VCF0844: How Willing Should U.S. Be to Use Military Force (26)
foreach num of numlist 2 10 31 3 36 38 26 {
replace issuetype = 2 if issuenum == `num'
}
// Race:
// VCF0811: Urban Unrest Scale (29)
// VCF0814: Civil Rights Pushes Too Fast or Not Fast Enough (8)
// VCF0815: Segregation or Desegregation (9)
// VCF0816: Should Government Ensure School Integration (1)
// VCF0817: School Busing Scale (30)
// VCF0818: Should Government Ensure Fair Jobs/Housing for Blacks (41)
// VCF0819: Open Housing (7)
// VCF0867a: Affirmative Action in Hiring/Promotion (22)
foreach num of numlist 29 8 9 1 30 41 7 22 {
replace issuetype = 3 if issuenum == `num'
}

twoway (scatter diff VCF0004 if issuetype == 1, mcolor(black) mfcolor(white) /*
*/ yline(0, lcolor(black) lpattern(dash))) /*
*/ (scatter diff VCF0004 if issuetype == 2, mcolor(gray) mfcolor(white)) /*
*/ (scatter diff VCF0004 if issuetype == 3, mcolor(black) mfcolor(black)) /*
*/ (scatter diff VCF0004 if issuetype == 4, mcolor(gray) mfcolor(gray)) /*
*/ (line decade_avg_diff VCF0004 if group == 1, lcolor(black)) /*
*/ (line decade_avg_diff VCF0004 if group == 2, lcolor(black)) /*
*/ (line decade_avg_diff VCF0004 if group == 3, lcolor(black)) /*
*/ (line decade_avg_diff VCF0004 if group == 4, lcolor(black)) /*
*/ (line decade_avg_diff VCF0004 if group == 5, lcolor(black)), /*
*/ legend(row(2) label(1 "Social Welfare") label(2 "Use of Force") /*
*/ label(3 "Race") label(4 "Other") /*
*/ order(- "Domain of Issue Position Question:" 1 2 - " " 3 4)) /*
*/ xtitle("Survey Year") ytitle("Difference in Males' and Females'" "Conservatism in ANES Issue Position Questions") /*
*/ xlabel(1960(10)2010) ylabel(-.1(.05).2) plotregion(color(white)) graphregion(color(white)) ylabel(,grid)  

graph export "TablesFigures/FigureA5a.eps", replace

twoway (scatter diff_college VCF0004 if issuetype == 1, mcolor(black) mfcolor(white)/*
*/ yline(0, lcolor(black) lpattern(dash))) /*
*/ (scatter diff_college VCF0004 if issuetype == 2, mcolor(gray) mfcolor(white)) /*
*/ (scatter diff_college VCF0004 if issuetype == 3, mcolor(black) mfcolor(black)) /*
*/ (scatter diff_college VCF0004 if issuetype == 4, mcolor(gray) mfcolor(gray)) /*
*/ (line decade_avg_diff_college VCF0004 if group == 1, lcolor(black)) /*
*/ (line decade_avg_diff_college VCF0004 if group == 2, lcolor(black)) /*
*/ (line decade_avg_diff_college VCF0004 if group == 3, lcolor(black)) /*
*/ (line decade_avg_diff_college VCF0004 if group == 4, lcolor(black)) /*
*/ (line decade_avg_diff_college VCF0004 if group == 5, lcolor(black)), /*
*/ legend(row(2) label(1 "Social Welfare") label(2 "Use of Force") /*
*/ label(3 "Race") label(4 "Other") /*
*/ order(- "Domain of Issue Position Question:" 1 2 - " " 3 4)) /*
*/ xtitle("Survey Year") ytitle("Difference in Males' and Females'" "Conservatism in ANES Issue Position Questions") /*
*/ xlabel(1960(10)2010) ylabel(-.2(.1).4) plotregion(color(white)) graphregion(color(white)) ylabel(,grid)  

graph export "TablesFigures/FigureA5b.eps", replace

log close
